package com.setting.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Org;
import com.file.entity.FileCustomer;
import com.setting.entity.JsonOrg;
import com.setting.entity.JsonOrgMenu;
import com.setting.entity.Children;
import com.setting.entity.SettingOrg;
import com.setting.service.OrgService;
import com.utils.JsonResult;

/**   
* @Title: OrgController.java 
* @Package com.controller 
* @author 孙梦楠 
* @date 2017年7月25日 上午11:10:56 
* @version V1.0.0   
*/

@RestController
@RequestMapping(value = "/setting/org")
public class OrgController {
	
	@Autowired
	private OrgService orgservice;
	
	//带用户列表
	@RequestMapping(value = "/list_org_customer", method = RequestMethod.GET)
	public JsonResult<List<Children>> listallorgcustomer(
			@CookieValue(value = "languagecookie", required = false) String languagecookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie) {
		
		return orgservice.list_org_customer(languagecookie,opeorgcookie,opetypecookie);
	}
	

	
	//架构列表
	@RequestMapping(value = "/list_org", method = RequestMethod.GET)
	public JsonResult<List<Children>> listallorg(
			@CookieValue(value = "languagecookie", required = false) String languagecookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie) {
		
		return orgservice.list_org(languagecookie,opeorgcookie,opetypecookie);
	}
	
//	@RequestMapping(value = "/list_customer_by_org", method = RequestMethod.POST)
//	public JsonResult<List<FileCustomer>> listCustomerByOrg(
//			@CookieValue(value = "languagecookie", required = false) String languagecookie,
//			@RequestBody Children org){
//		
//		String orgvalue = org.getOrgvalue();
//		String status = org.getStatus();
//		
//		return orgservice.listCustomerByOrg(orgvalue, languagecookie,status);
//	}
	
	

	//新增公司
	@RequestMapping(value = "/add_company", method = RequestMethod.POST)
	public JsonResult<JsonOrg> addfatherorg(@RequestBody JsonOrg jsonorg,
			@CookieValue(value = "languagecookie", required = false) String languagecookie){
		
		String orgname = jsonorg.getOrgname();
		String orgfather = "0";
		String en_orgname = jsonorg.getEn_orgname();
		String leadername = jsonorg.getLeadername();
		String phonenum = jsonorg.getPhonenum();
		String cn_areanum = jsonorg.getCn_areanum();
		
		return orgservice.addfatherorg(orgname, orgfather,en_orgname,leadername,phonenum,cn_areanum,languagecookie);
		
	}
	
	//新增小区
	@RequestMapping(value = "/add_village", method = RequestMethod.POST)
	public JsonResult<JsonOrg> addsonorg(@RequestBody JsonOrg jsonorg,
			@CookieValue(value = "languagecookie", required = false) String languagecookie){
		
		String orgname = jsonorg.getOrgname();
		String orgfather = jsonorg.getOrgfather();
		String en_orgname = jsonorg.getEn_orgname();
		String leadername = jsonorg.getLeadername();
		String phonenum = jsonorg.getPhonenum();
		String cn_areanum = jsonorg.getCn_areanum();
		
		return orgservice.addfatherorg(orgname, orgfather,en_orgname,leadername,phonenum,cn_areanum,languagecookie);
		
	}
	
	//公司菜单列表
	@RequestMapping(value = "/company_menu", method = RequestMethod.GET)
	public JsonResult<List<JsonOrgMenu>> listcompany(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {
		
		return orgservice.listcompanymenu(languagecookie);
	}
	
	//公司列表
	@RequestMapping(value = "/list_company", method = RequestMethod.GET)
	public JsonResult<List<JsonOrgMenu>> list_company(
			@CookieValue(value = "languagecookie", required = false) String languagecookie){
		
		return orgservice.listarea("0",languagecookie);
		
	}
	
	
	//小区列表
	@RequestMapping(value = "/list_village", method = RequestMethod.POST)
	public JsonResult<List<JsonOrgMenu>> list_village(@RequestBody JsonOrgMenu jsonorgmenu,
			@CookieValue(value = "languagecookie", required = false) String languagecookie){
		String orgfather = jsonorgmenu.getOrgvalue();
		
		return orgservice.listarea(orgfather,languagecookie);
		
	}
	
	
	//删除公司
	@RequestMapping(value = "/delete_company", method = RequestMethod.POST)
	public JsonResult<JsonOrgMenu> deletecompany(@RequestBody JsonOrgMenu jsonorgmenu) {
		String orgvalue =jsonorgmenu.getOrgvalue();
		return orgservice.deletecompany(orgvalue);
	}
	
	//删除小区
	@RequestMapping(value = "/delete_village", method = RequestMethod.POST)
	public JsonResult<JsonOrgMenu> deletevillage(@RequestBody JsonOrgMenu jsonorgmenu) {
		String orgvalue =jsonorgmenu.getOrgvalue();
		return orgservice.deletecarea(orgvalue);
	}
	
}
